#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tree.h"

#define FILENAME "/home/ll/text"

/*将一棵树以广义表的形式存在文件中
 *
 *
 */

	int save_(tree_st *root,FILE *fp)
{
	fputc('(',fp);
	if(root == NULL)
	{
		fputc(')',fp);
		return 0;
	}

	fputc(root->data,fp);
	
	save_(root->lchild,fp);
	save_(root->rchild,fp);
	
	fputc(')',fp);


}

	int save(tree_st *root,const char *path)
{
	FILE *fp = NULL;
	fp = fopen(path,"w");
	if(fp == NULL)
		return -1;
	save_(root,fp);
	return 0;
}







	int main()
{
	char a[] = "cefadjbh";
	tree_st *tree = NULL;
	for(int i = 0;i < strlen(a);i++)
	{	
		tree_insert(&tree,a[i]);
	}

	tree_draw(tree);
	save(tree,FILENAME);
	exit(0);
}
